<template>
	<div>
		<div class="publish-top">
			<div class="left-icon" @click="handleBack"> 
				<img src="../../../assets/images/left.png"/>
			</div>
			<p>发送邮件</p>
			<span @click="handleSubmit">发送</span>
		</div>
		<div class="send-content">
			<ul class="send-list">
				<li>
					<div class="list-left">
						<span>收件人:</span>
						<span>{{name}}</span>
					</div>
					<!--<img src="../../../assets/images/message/message-icon.png"/>-->
				</li>
				<li>
					<div class="list-left">
						<span>标题:</span>
						<input type="text" placeholder="请填写标题(最多15个文字~)" @change="changeTitle" maxlength="15"/>
					</div>
					<!--<img src="../../../assets/images/message/message-icon.png"/>-->
				</li>
			</ul>
			
		  	<div id="text">
		  		<textarea placeholder="请输入发送内容~" class="text" @change="changeText" ></textarea>
		  	</div>
		</div>
	</div>
</template>

<script>
	import axios from "axios";
	import user from '../../../utils/isLogin';
	import qs from 'qs';
	export default{
		data(){
			return{
				recipientId:0,
				name: '',
				title:'',
				texts: ''
			}
		},
		created(){
			var curr = plus.webview.currentWebview();
		   this.recipientId = curr.recipientId; 
		   this.name = curr.name;
			let plusReady = ()=>{
				
			}
			if (window.plus) {
		      plusReady();
		    } else {
		      document.addEventListener("plusready", plusReady, false);
		    }

		},
		components:{
			
		},
		methods:{
			handleBack(){
				var send = plus.webview.getWebviewById('send');
				plus.webview.close(send);
			},
			changeTitle(e){
				this.title = e.target.value;
			},
			changeText(e){
				this.texts =e.target.value;
			},
			handleSubmit(){
				var userId = JSON.parse(window.localStorage.getItem( 'userInfo' )).userId;
				var {recipientId,title,texts,name} = this;
				if(title == ''){
					plus.nativeUI.toast('请输入标题~');
					return;
				}
				if(texts == ''){
					plus.nativeUI.toast('请输入内容~');
					return;
				}
				var data = qs.stringify({
					userid: userId,
					recipientId: this.recipientId,
					title: this.title,
					dese: this.texts
				})
				plus.nativeUI.showWaiting( "私信发送中..." );
				axios({
				   method: 'post',
				   url: user.src + '/index/my/Sending_private_messages',
				   data:data
				})
			   .then(res => {
			   	var name = res.data.userNickname;
			   	if(res.data.status == 1069){
			   		plus.nativeUI.closeWaiting();
			   		plus.nativeUI.toast(res.data.mesg);
			   	}
		      	if(res.data.status == 200){
						var data = qs.stringify({
							userid:this.recipientId,
							title:'【'+ name +'】'+'发来一封新邮件',
							desc:this.title,
							type:4
						})
						axios({
						   method: 'post',
						   url: user.src + '/index/Getui/pushPhone',
						   data:data
						})
						.then(res =>{
							if(res.data.data.result == 'ok'){
								setTimeout(function(){
									plus.nativeUI.closeWaiting();
									var send = plus.webview.getWebviewById('send');
									plus.webview.close(send);
								},1000)
							}
						})
						.catch(err => {
					      console.log(err)
					   })
					}
			   })
			   .catch(err => {
			      console.log(err)
			   })
			}
		}
	}
</script>

<style lang='less' scoped>

html,body{
		padding: 0;
		margin: 0;
		width: 100%;
		height: 100%;
		background: #fff;

	}
	*{
		margin: 0;
		padding: 0;
	}
	ul,li{
		list-style: none;
	}
	.publish-top{
		position: fixed;
		top: 0;
		left: 0;
		width: 100%;
		height: 60px;
		background:@default-blue;
		box-shadow: 0px 0px 8px 1px #999;
		padding-top: 70px;
		display:flex;
		justify-content: space-between;				
		.left-icon{
			width: 90px;
			img{
				width: 15px;
				height: 26px;
				margin-left: 31px;
			}
		}
		p{		
			color: #fff;
			font-size: 28px;
			text-align: center;
			text-indent: 50px;
		}
		span{
			display: block;
			width: 170px;
			color: #fff;
			font-size: 28px;
			text-align: center;
		}
	}
	.send-content{
		padding-top: 130px;
		#text{
			padding: 40px  24px 0 24px;
			.text{
				display: block;
				padding-top: 20px;
				padding-bottom: 21px;
				width: 100%;
				height: 380px;
				/*padding-left: 20px;*/
				/*padding-right: 20px;*/
				text-indent: 20px;
				border: none;
				font-size: 32px;
				line-height: 44px;
				outline:none;
				background: #F6F6F6;
				border-radius: 5px;
				resize: none;
			}
		}
		.send-list{
			padding: 0 26px;
			li{
				display: flex;
				justify-content: space-between;
				height: 109px;
				line-height: 109px;
				border-bottom: 1px solid #ececec;
				.list-left{	
					span{
						display: inline-block;
						height: 109px;
						line-height: 109px;
						margin-right: 30px;
						font-size: 27px;
						color: #333;
					}
					input{
						border:none;
						outline: none;
						height: 100px;
						line-height: 100px;
						font-size: 25px;
						width: 500px;
					}
				}
				img{
					margin-top: 40px;	
					display: block;
					width: 17px;
					height: 26px;
				}
			}
		}
	}
</style>